home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / drivers / mscdex / testdrv / prepare.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-25  |  4.6 KB  |  164 lines

  1. /*
  2. ** TESTDRV - CD-ROM Device driver test
  3. **
  4. **
  5. ** prepare.c Unsupported commands for creating a control archive
  6. **
  7. **
  8. ** HISTORY:
  9. **  10/01/90 Final (v1.0) -by- JYG
  10. **  12/06/91 Revised  by Siddhartha Roy
  11. */
  12. #include<malloc.h>
  13. #include"test.h"
  14.  
  15. static int bytes;
  16. char _near *pchBuf;
  17.  
  18. void   SectorToArc(drv,lSector,bAddrMode,bReadMode,pOutFile)
  19. Dev_List   *drv;
  20. DWORD  lSector;
  21. BYTE   bAddrMode;
  22. BYTE   bReadMode;
  23. FILE   *pOutFile;
  24. {
  25.  
  26.    printf("\nReading Sector\n");
  27.    if (ERRORBIT & WDvRqReadL(drv,pchBuf,lSector,1,bAddrMode,bReadMode,0,0))
  28.    {
  29.       printf("Read Error. Skipping Sector\n");
  30.       return;
  31.    }
  32.  
  33.    printf("\nWriting Sector %lx\n",lSector);
  34.        fwrite(&bAddrMode,1,1,pOutFile);bytes++;
  35.    fwrite(&lSector,sizeof(DWORD),1,pOutFile);bytes+=sizeof(DWORD);
  36.    fwrite(&bReadMode,1,1,pOutFile);bytes++;
  37.    if (bReadMode == RAW_MODE) 
  38.    {
  39.       printf("\nRAW_MODE %lx\n",lSector);
  40.       fwrite(pchBuf,1,RAW_SECTOR_SIZE,pOutFile);bytes+=RAW_SECTOR_SIZE;
  41.    }
  42.    else 
  43.    {
  44.       printf("\nCOOKED_MODE %lx\n",lSector);
  45.       fwrite(pchBuf,1,COOKED_SECTOR_SIZE,pOutFile);bytes+=COOKED_SECTOR_SIZE;
  46.    }
  47. }
  48.  
  49. /*
  50. **   prepData()  -  prepares the control data files
  51. **   for the automated testing.
  52. **
  53. **   CD-ROM requirements are:
  54. **      must support Redbook Addressing
  55. **      must support Raw mode reads
  56. */
  57.  
  58. void prepData(drv)
  59. Dev_List   *drv;
  60. {
  61.    extern WORD cwHSGSectors, cwRedSectors;
  62.    extern FILE * pOutFile;
  63.    extern DWORD mplHSGSector[];
  64.    extern DWORD mplRedSector[];
  65.    extern WORD wDriveNum;
  66.     
  67.    char *  title;
  68.    char   szDiskTitle[256];
  69.    char    szVolLabel [13];
  70.    DWORD   vsize;
  71.    BYTE   iTrack,len;
  72.    WORD   iSector;
  73.  
  74.     
  75.    UPCCode_Rec   upc;
  76.    DiskInfo_Rec   dinfo;
  77.    TnoInfo_Rec   tnoinfo;
  78.    bytes = 0;
  79.     
  80.    if (pOutFile == stdout)
  81.       fatalError("Please specify an archive file in the profile");
  82.    else if (cwHSGSectors == 0 && cwRedSectors == 0)
  83.       fatalError("Please specify the sectors to archive in the profile");
  84.  
  85.    // Write header
  86.  
  87.    printf("Enter a single line disk title: ");
  88.    *szDiskTitle = (char)253;
  89.    
  90.    cgets(szDiskTitle);
  91.    printf("\n");
  92.  
  93.    // The archive file consists of:
  94.    // [sizeof(title)][Title][UPCCode_Rec][DiskInfo_Rec][Volsize DWORD]
  95.    // [...all Track info for each track...]
  96.  
  97.    len = *((char *)(szDiskTitle+1));
  98.    title = szDiskTitle+2;
  99.    title[len] = '\0';
  100.     
  101.    VolLabel( wDriveNum, szVolLabel );
  102.  
  103.    printf("Getting Disc Characteristics\n");
  104.    if (ERRORBIT&WDvRqIoiUPCCode(drv,&upc))
  105.     {   
  106.         printf("Not including UPC info\n");
  107.       upc.code = 0;
  108.     }
  109.    if (ERRORBIT&WDvRqIoiDiskInfo(drv,&dinfo))
  110.     {
  111.         printf("Not including disk info\n");
  112.       dinfo.code = 0;
  113.     }
  114.    if (ERRORBIT&WDvRqIoiVolSize(drv,&vsize))
  115.     {
  116.         printf("Not including volume size\n");
  117.       vsize = 0L;
  118.     }
  119.    
  120.    printf("Writing Disc Characteristics\n");
  121.    fileErrorTest(fwrite(&len,1,1,pOutFile));bytes++; 
  122.    fileErrorTest(fwrite(title,1,len,pOutFile));bytes+=len;
  123.    
  124.    fileErrorTest(fwrite(&upc,sizeof(UPCCode_Rec),1,pOutFile));bytes+=sizeof(UPCCode_Rec);
  125.    fileErrorTest(fwrite(&dinfo,sizeof(DiskInfo_Rec),1,pOutFile));bytes+=sizeof(DiskInfo_Rec);
  126.    fileErrorTest(fwrite(&vsize,sizeof(DWORD),1,pOutFile));bytes+=sizeof(DWORD);
  127.    fileErrorTest(fwrite(szVolLabel,1,13,pOutFile));bytes+=13;
  128.     
  129.  
  130.    // All track information
  131.  
  132.    printf("Getting Track Characteristics\n");
  133.    for (iTrack=dinfo.low_track;iTrack<=dinfo.hi_track;iTrack++){
  134.       if (ERRORBIT&WDvRqIoiTnoInfo(drv,iTrack,&tnoinfo))
  135.             fatalError("Bad Track Info");
  136.       fileErrorTest(fwrite(&tnoinfo,sizeof(TnoInfo_Rec),1,pOutFile));bytes+=sizeof(TnoInfo_Rec);
  137.    }
  138.  
  139.    printf("\n%d bytes header information",bytes);
  140.    
  141.     pchBuf = _nmalloc(RAW_SECTOR_SIZE);
  142.     //
  143.     // Write the first COOKED Sector for a sanity check
  144.     //
  145.     SectorToArc( drv,0L,HSG_ADDRMODE,COOKED_MODE,pOutFile );
  146.     //
  147.     // Write all of the Sectors specified in the profile
  148.     //
  149.     for (iSector = 0; iSector < cwHSGSectors; iSector++)
  150.    {
  151.       SectorToArc(drv,mplHSGSector[iSector],HSG_ADDRMODE,COOKED_MODE,pOutFile);
  152.       SectorToArc(drv,mplHSGSector[iSector],HSG_ADDRMODE,RAW_MODE,pOutFile);
  153.    }
  154.    for (iSector = 0; iSector < cwRedSectors; iSector++)
  155.    {
  156.       SectorToArc(drv,mplRedSector[iSector],REDBOOK_ADDRMODE,COOKED_MODE,pOutFile);
  157.       SectorToArc(drv,mplRedSector[iSector],REDBOOK_ADDRMODE,RAW_MODE,pOutFile);
  158.    }
  159.    fclose(pOutFile);
  160.    
  161.    printf("Done Creating Archive, %d bytes written\n",bytes);
  162.    _nfree(pchBuf);
  163.